package cn.imvc.app.controllers.info;

import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;

import cn.imvc.app.controllers.goods.GoodsControllerImpl;
import cn.imvc.app.domains.IndexDataType;
import cn.imvc.app.domains.ShowType;
import cn.imvc.app.entities.IndexClass;
import cn.imvc.app.models.IndexClassModel;
import cn.imvc.app.models.LoggingModel;
import cn.imvc.core.DialogBean;
import cn.imvc.core.Render;
import cn.imvc.data.domain.ViewRequest;

public class IndexClassControllerImpl implements IndexClassController {

	static Logger logger = Logger.getLogger(IndexClassControllerImpl.class);
	public Page<IndexClass> page;
	public IndexClass indexClass;

	public ViewRequest viewRequest;
	public int id;
	public int[] ids;
	public Map<Integer, String> showType = ShowType.elMap;
	public Map<Byte, String> indexDataType = IndexDataType.elMap;
	@Autowired
	IndexClassModel indexClassModel;
	@Autowired
	LoggingModel loggingModel;
	public String search() {
		// TODO Auto-generated method stub
		return null;
	}

	public String index() {
		if(viewRequest==null){
			viewRequest = new ViewRequest();
		}
		viewRequest.getSort().put("sort","ASC");
		page=indexClassModel.find(viewRequest);
		return "index-class/index";
	}

	public String show() {
		// TODO Auto-generated method stub
		return null;
	}

	public String editNew() {
		return "index-class/edit";
	}

	public String create() {
		indexClassModel.save(indexClass);
		loggingModel.info(logger,"添加首页："+indexClass.getTitle());
		return Render.json(new DialogBean("200", "创建成功","", "closeCurrent"));
	}

	public String edit() {
		indexClass = indexClassModel.get(id);
		return "index-class/edit";
	}

	public String update() {
		indexClassModel.update(id,indexClass);
		loggingModel.info(logger,"修改首页："+indexClass.getTitle());
		return Render.json(new DialogBean("200", "修改成功","", "closeCurrent"));
	}

	public String destroy() {
		String result = indexClassModel.delete(id);
		if(result.equals("")){
			loggingModel.info(logger,"删除首页："+id);
		    return Render.json(new DialogBean("200", "删除成功","","",""));
		}else{
			return Render.json(new DialogBean("300",result,"","",""));
		}
	}

	public String destroyBatch() {
		indexClassModel.deleteBatch(ids);
		return Render.json(new DialogBean("200", "删除成功",""));
	}
	public void setIndexClassModel(IndexClassModel indexClassModel) {
		this.indexClassModel = indexClassModel;
	}

	public void setPage(Page<IndexClass> page) {
		this.page = page;
	}

	public void setIndexClass(IndexClass indexClass) {
		this.indexClass = indexClass;
	}

	public void setViewRequest(ViewRequest viewRequest) {
		this.viewRequest = viewRequest;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setIds(int[] ids) {
		this.ids = ids;
	}

	public Map<Integer, String> getShowType() {
		return showType;
	}

	public void setShowType(Map<Integer, String> showType) {
		this.showType = showType;
	}

	public Map<Byte, String> getIndexDataType() {
		return indexDataType;
	}

	public void setIndexDataType(Map<Byte, String> indexDataType) {
		this.indexDataType = indexDataType;
	}
}
